package com.cskaoyan.service.wx;

import com.cskaoyan.bean.goods.wx.WxGoodsCategoryData;
import com.cskaoyan.bean.po.MarketCartExample;
import com.cskaoyan.bean.po.MarketCategory;
import com.cskaoyan.bean.po.MarketCategoryExample;
import com.cskaoyan.mapper.MarketCategoryMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: WxCategoryServiceImpl
 * Description:
 * date: 2022/6/9 10:42
 *
 * @author bruce
 * @since JDK 8
 */
@Service
public class WxCategoryServiceImpl implements WxCategoryService {
    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    @Override
    public WxGoodsCategoryData wxGoodsCategoryquery(Integer categoryId) {
        MarketCategory current = marketCategoryMapper.selectByPrimaryKey(categoryId);
        //获得父id
        Integer pid = current.getPid();
        //顶级类目
        if (pid == null) {
            return WxGoodsCategoryData.data(current,null,null);
        }
        //找到父类列表
        MarketCategory parent = marketCategoryMapper.selectByPrimaryKey(pid);

        MarketCategoryExample categoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = categoryExample.createCriteria();
        criteria.andPidEqualTo(pid);
        List<MarketCategory> brotherCategory = marketCategoryMapper.selectByExample(categoryExample);

        return WxGoodsCategoryData.data(current,parent,brotherCategory);
    }
}
